import { Context } from 'koa';
import { BaseRouter } from './base.router';
import { userController } from '@/controllers';
import { 
  authMiddleware, 
  adminMiddleware,
  loginLimiter,
  strictLimiter 
} from '@/middlewares';
import {
  validateBody,
  validateQuery,
  validateParams,
  userRegisterSchema,
  userLoginSchema,
  userUpdateSchema,
  passwordChangeSchema,
  userListQuerySchema,
  userStatusUpdateSchema,
  idParamsSchema,
} from '@/validators';

/**
 * 用户路由
 */
export class UserRouter extends BaseRouter {
  constructor() {
    super('/api/v1/users');
  }

  protected setupRoutes(): void {
    // 公开路由
    this.setupPublicRoutes();
    
    // 认证路由
    this.setupAuthRoutes();
    
    // 管理员路由
    this.setupAdminRoutes();
  }

  /**
   * 公开路由（无需认证）
   */
  private setupPublicRoutes(): void {
    /**
     * @swagger
     * /api/v1/users/register:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 用户注册
     *     description: 创建新的用户账户
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - username
     *               - email
     *               - password
     *               - firstName
     *               - lastName
     *             properties:
     *               username:
     *                 type: string
     *                 minLength: 3
     *                 maxLength: 20
     *                 description: 用户名
     *               email:
     *                 type: string
     *                 format: email
     *                 description: 邮箱地址
     *               password:
     *                 type: string
     *                 minLength: 6
     *                 description: 密码
     *               firstName:
     *                 type: string
     *                 maxLength: 50
     *                 description: 名字
     *               lastName:
     *                 type: string
     *                 maxLength: 50
     *                 description: 姓氏
     *               phone:
     *                 type: string
     *                 pattern: '^1[3-9]\\d{9}$'
     *                 description: 手机号
     *           example:
     *             username: "johndoe"
     *             email: "john@example.com"
     *             password: "Password123!"
     *             firstName: "John"
     *             lastName: "Doe"
     *             phone: "13800138000"
     *     responses:
     *       201:
     *         description: 注册成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       400:
     *         description: 请求参数错误
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       409:
     *         description: 邮箱或用户名已存在
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 用户注册
    this.router.post(
      '/register',
      loginLimiter,
      validateBody(userRegisterSchema),
      this.wrapAsync(userController.register.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/login:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 用户登录
     *     description: 用户登录获取访问令牌
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - email
     *               - password
     *             properties:
     *               email:
     *                 type: string
     *                 format: email
     *                 description: 邮箱地址
     *               password:
     *                 type: string
     *                 description: 密码
     *               rememberMe:
     *                 type: boolean
     *                 default: false
     *                 description: 记住登录状态
     *           example:
     *             email: "john@example.com"
     *             password: "Password123!"
     *             rememberMe: false
     *     responses:
     *       200:
     *         description: 登录成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       type: object
     *                       properties:
     *                         user:
     *                           $ref: '#/components/schemas/User'
     *                         token:
     *                           type: string
     *                           description: JWT 访问令牌
     *                         expiresIn:
     *                           type: string
     *                           description: 令牌过期时间
     *       401:
     *         description: 认证失败
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 用户登录
    this.router.post(
      '/login',
      loginLimiter,
      validateBody(userLoginSchema),
      this.wrapAsync(userController.login.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/password/reset:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 请求密码重置
     *     description: 发送密码重置邮件到用户邮箱
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - email
     *             properties:
     *               email:
     *                 type: string
     *                 format: email
     *                 description: 注册邮箱地址
     *           example:
     *             email: "john@example.com"
     *     responses:
     *       200:
     *         description: 密码重置邮件发送成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       400:
     *         description: 邮箱格式错误
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       404:
     *         description: 邮箱未注册
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 密码重置请求
    this.router.post(
      '/password/reset',
      strictLimiter,
      this.wrapAsync(this.requestPasswordReset)
    );

    /**
     * @swagger
     * /api/v1/users/password/reset/confirm:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 确认密码重置
     *     description: 使用重置令牌设置新密码
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - token
     *               - newPassword
     *             properties:
     *               token:
     *                 type: string
     *                 description: 密码重置令牌
     *               newPassword:
     *                 type: string
     *                 minLength: 6
     *                 description: 新密码
     *           example:
     *             token: "reset_token_123456"
     *             newPassword: "NewPassword123!"
     *     responses:
     *       200:
     *         description: 密码重置成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       400:
     *         description: 令牌无效或已过期
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 密码重置确认
    this.router.post(
      '/password/reset/confirm',
      strictLimiter,
      this.wrapAsync(this.confirmPasswordReset)
    );

    /**
     * @swagger
     * /api/v1/users/email/verify:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 验证邮箱
     *     description: 使用验证令牌验证用户邮箱
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - token
     *             properties:
     *               token:
     *                 type: string
     *                 description: 邮箱验证令牌
     *           example:
     *             token: "verify_token_123456"
     *     responses:
     *       200:
     *         description: 邮箱验证成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       400:
     *         description: 令牌无效或已过期
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 邮箱验证
    this.router.post(
      '/email/verify',
      strictLimiter,
      this.wrapAsync(this.verifyEmail)
    );

    /**
     * @swagger
     * /api/v1/users/email/resend:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 重新发送验证邮件
     *     description: 重新发送邮箱验证邮件
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - email
     *             properties:
     *               email:
     *                 type: string
     *                 format: email
     *                 description: 需要验证的邮箱地址
     *           example:
     *             email: "john@example.com"
     *     responses:
     *       200:
     *         description: 验证邮件发送成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       400:
     *         description: 邮箱格式错误
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       404:
     *         description: 邮箱未注册
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 重新发送验证邮件
    this.router.post(
      '/email/resend',
      strictLimiter,
      this.wrapAsync(this.resendVerificationEmail)
    );
  }

  /**
   * 认证路由（需要登录）
   */
  private setupAuthRoutes(): void {
    /**
     * @swagger
     * /api/v1/users/me:
     *   get:
     *     tags:
     *       - 用户管理
     *     summary: 获取当前用户信息
     *     description: 获取当前登录用户的详细信息
     *     security:
     *       - bearerAuth: []
     *     responses:
     *       200:
     *         description: 获取成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       $ref: '#/components/schemas/User'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 获取当前用户信息
    this.router.get(
      '/me',
      authMiddleware,
      this.wrapAsync(userController.getCurrentUserInfo.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/me:
     *   put:
     *     tags:
     *       - 用户管理
     *     summary: 更新用户信息
     *     description: 更新当前登录用户的个人信息
     *     security:
     *       - bearerAuth: []
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             properties:
     *               username:
     *                 type: string
     *                 minLength: 3
     *                 maxLength: 20
     *                 description: 用户名
     *               firstName:
     *                 type: string
     *                 maxLength: 50
     *                 description: 名字
     *               lastName:
     *                 type: string
     *                 maxLength: 50
     *                 description: 姓氏
     *               phone:
     *                 type: string
     *                 pattern: '^1[3-9]\\d{9}$'
     *                 description: 手机号
     *               bio:
     *                 type: string
     *                 maxLength: 500
     *                 description: 个人简介
     *           example:
     *             username: "johndoe_updated"
     *             firstName: "John"
     *             lastName: "Doe"
     *             phone: "13800138001"
     *             bio: "这是我的个人简介"
     *     responses:
     *       200:
     *         description: 更新成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       $ref: '#/components/schemas/User'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       409:
     *         description: 用户名已存在
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 更新用户资料
    this.router.put(
      '/me',
      authMiddleware,
      validateBody(userUpdateSchema),
      this.wrapAsync(userController.updateProfile.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/me/password:
     *   put:
     *     tags:
     *       - 用户管理
     *     summary: 修改密码
     *     description: 修改当前用户的登录密码
     *     security:
     *       - bearerAuth: []
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - currentPassword
     *               - newPassword
     *             properties:
     *               currentPassword:
     *                 type: string
     *                 description: 当前密码
     *               newPassword:
     *                 type: string
     *                 minLength: 6
     *                 description: 新密码
     *           example:
     *             currentPassword: "Password123!"
     *             newPassword: "NewPassword456!"
     *     responses:
     *       200:
     *         description: 密码修改成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       400:
     *         description: 当前密码错误
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 修改密码
    this.router.put(
      '/me/password',
      authMiddleware,
      strictLimiter,
      validateBody(passwordChangeSchema),
      this.wrapAsync(userController.changePassword.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/me/avatar:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 上传头像
     *     description: 上传用户头像图片
     *     security:
     *       - bearerAuth: []
     *     requestBody:
     *       required: true
     *       content:
     *         multipart/form-data:
     *           schema:
     *             type: object
     *             properties:
     *               avatar:
     *                 type: string
     *                 format: binary
     *                 description: 头像图片文件（支持JPG、PNG格式）
     *     responses:
     *       200:
     *         description: 头像上传成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       type: object
     *                       properties:
     *                         avatar:
     *                           type: string
     *                           description: 头像图片URL
     *       400:
     *         description: 文件格式不支持或文件过大
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 上传头像
    this.router.post(
      '/me/avatar',
      authMiddleware,
      this.wrapAsync(this.uploadAvatar)
    );

    /**
     * @swagger
     * /api/v1/users/me/avatar:
     *   delete:
     *     tags:
     *       - 用户管理
     *     summary: 删除头像
     *     description: 删除用户头像，恢复为默认头像
     *     security:
     *       - bearerAuth: []
     *     responses:
     *       200:
     *         description: 头像删除成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 删除头像
    this.router.delete(
      '/me/avatar',
      authMiddleware,
      this.wrapAsync(this.deleteAvatar)
    );

    /**
     * @swagger
     * /api/v1/users/logout:
     *   post:
     *     tags:
     *       - 用户管理
     *     summary: 用户登出
     *     description: 注销当前用户登录状态
     *     security:
     *       - bearerAuth: []
     *     responses:
     *       200:
     *         description: 登出成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 注销登录
    this.router.post(
      '/logout',
      authMiddleware,
      this.wrapAsync(this.logout)
    );
  }

  /**
   * 管理员路由（需要管理员权限）
   */
  private setupAdminRoutes(): void {
    /**
     * @swagger
     * /api/v1/users:
     *   get:
     *     tags:
     *       - 用户管理(管理员)
     *     summary: 获取用户列表
     *     description: 分页获取用户列表，支持搜索和过滤（仅管理员）
     *     security:
     *       - bearerAuth: []
     *     parameters:
     *       - in: query
     *         name: page
     *         schema:
     *           type: integer
     *           minimum: 1
     *           default: 1
     *         description: 页码
     *       - in: query
     *         name: limit
     *         schema:
     *           type: integer
     *           minimum: 1
     *           maximum: 100
     *           default: 10
     *         description: 每页数量
     *       - in: query
     *         name: keyword
     *         schema:
     *           type: string
     *         description: 搜索关键词
     *       - in: query
     *         name: status
     *         schema:
     *           type: string
     *           enum: [active, inactive, suspended, pending, deleted]
     *         description: 用户状态
     *       - in: query
     *         name: role
     *         schema:
     *           type: string
     *           enum: [admin, user, moderator, guest]
     *         description: 用户角色
     *       - in: query
     *         name: sortBy
     *         schema:
     *           type: string
     *           enum: [createdAt, updatedAt, username, email]
     *           default: createdAt
     *         description: 排序字段
     *       - in: query
     *         name: sortOrder
     *         schema:
     *           type: string
     *           enum: [asc, desc]
     *           default: desc
     *         description: 排序方向
     *     responses:
     *       200:
     *         description: 获取成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/PaginatedResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       type: array
     *                       items:
     *                         $ref: '#/components/schemas/User'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       403:
     *         description: 权限不足
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 获取用户列表
    this.router.get(
      '/',
      authMiddleware,
      adminMiddleware,
      validateQuery(userListQuerySchema),
      this.wrapAsync(userController.getUsers.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/{id}:
     *   get:
     *     tags:
     *       - 用户管理(管理员)
     *     summary: 获取用户详情
     *     description: 根据ID获取指定用户的详细信息（仅管理员）
     *     security:
     *       - bearerAuth: []
     *     parameters:
     *       - in: path
     *         name: id
     *         required: true
     *         schema:
     *           type: string
     *           pattern: '^[0-9a-fA-F]{24}$'
     *         description: 用户ID
     *     responses:
     *       200:
     *         description: 获取成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       $ref: '#/components/schemas/User'
     *       400:
     *         description: 无效的ID格式
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       403:
     *         description: 权限不足
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       404:
     *         description: 用户不存在
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 获取用户详情
    this.router.get(
      '/:id',
      authMiddleware,
      adminMiddleware,
      validateParams(idParamsSchema),
      this.wrapAsync(userController.getUserById.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/{id}/status:
     *   put:
     *     tags:
     *       - 用户管理(管理员)
     *     summary: 更新用户状态
     *     description: 更新指定用户的状态（仅管理员）
     *     security:
     *       - bearerAuth: []
     *     parameters:
     *       - in: path
     *         name: id
     *         required: true
     *         schema:
     *           type: string
     *           pattern: '^[0-9a-fA-F]{24}$'
     *         description: 用户ID
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - status
     *             properties:
     *               status:
     *                 type: string
     *                 enum: [active, inactive, suspended, pending, deleted]
     *                 description: 新状态
     *               reason:
     *                 type: string
     *                 maxLength: 500
     *                 description: 更新原因
     *           example:
     *             status: "suspended"
     *             reason: "违反社区规则"
     *     responses:
     *       200:
     *         description: 更新成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       $ref: '#/components/schemas/User'
     *       400:
     *         description: 无效的状态或ID
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       403:
     *         description: 权限不足
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       404:
     *         description: 用户不存在
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 更新用户状态
    this.router.put(
      '/:id/status',
      authMiddleware,
      adminMiddleware,
      validateParams(idParamsSchema),
      validateBody(userStatusUpdateSchema),
      this.wrapAsync(userController.updateUserStatus.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/{id}:
     *   delete:
     *     tags:
     *       - 用户管理(管理员)
     *     summary: 删除用户
     *     description: 删除指定的用户账户（仅管理员）
     *     security:
     *       - bearerAuth: []
     *     parameters:
     *       - in: path
     *         name: id
     *         required: true
     *         schema:
     *           type: string
     *           pattern: '^[0-9a-fA-F]{24}$'
     *         description: 用户ID
     *     responses:
     *       200:
     *         description: 删除成功
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ApiResponse'
     *       400:
     *         description: 无效的ID格式
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       403:
     *         description: 权限不足
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       404:
     *         description: 用户不存在
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 删除用户
    this.router.delete(
      '/:id',
      authMiddleware,
      adminMiddleware,
      validateParams(idParamsSchema),
      this.wrapAsync(userController.deleteUser.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/stats/overview:
     *   get:
     *     tags:
     *       - 用户管理(管理员)
     *     summary: 获取用户统计信息
     *     description: 获取用户相关的统计数据（仅管理员）
     *     security:
     *       - bearerAuth: []
     *     responses:
     *       200:
     *         description: 获取成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       type: object
     *                       properties:
     *                         totalUsers:
     *                           type: integer
     *                           description: 用户总数
     *                         activeUsers:
     *                           type: integer
     *                           description: 活跃用户数
     *                         newUsersToday:
     *                           type: integer
     *                           description: 今日新增用户
     *                         usersByStatus:
     *                           type: object
     *                           description: 按状态分组的用户数
     *                         usersByRole:
     *                           type: object
     *                           description: 按角色分组的用户数
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       403:
     *         description: 权限不足
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 获取用户统计
    this.router.get(
      '/stats/overview',
      authMiddleware,
      adminMiddleware,
      this.cache(300), // 缓存5分钟
      this.wrapAsync(userController.getUserStats.bind(userController))
    );

    /**
     * @swagger
     * /api/v1/users/batch/status:
     *   post:
     *     tags:
     *       - 用户管理(管理员)
     *     summary: 批量更新用户状态
     *     description: 批量更新多个用户的状态（仅管理员）
     *     security:
     *       - bearerAuth: []
     *     requestBody:
     *       required: true
     *       content:
     *         application/json:
     *           schema:
     *             type: object
     *             required:
     *               - userIds
     *               - status
     *             properties:
     *               userIds:
     *                 type: array
     *                 items:
     *                   type: string
     *                   pattern: '^[0-9a-fA-F]{24}$'
     *                 description: 用户ID列表
     *               status:
     *                 type: string
     *                 enum: [active, inactive, suspended, pending, deleted]
     *                 description: 目标状态
     *               reason:
     *                 type: string
     *                 maxLength: 500
     *                 description: 操作原因
     *           example:
     *             userIds: ["60d5f5f5f5f5f5f5f5f5f5f5", "60d5f5f5f5f5f5f5f5f5f5f6"]
     *             status: "suspended"
     *             reason: "批量处理违规用户"
     *     responses:
     *       200:
     *         description: 批量更新成功
     *         content:
     *           application/json:
     *             schema:
     *               allOf:
     *                 - $ref: '#/components/schemas/ApiResponse'
     *                 - type: object
     *                   properties:
     *                     data:
     *                       type: object
     *                       properties:
     *                         success:
     *                           type: integer
     *                           description: 成功更新数量
     *                         failed:
     *                           type: integer
     *                           description: 失败更新数量
     *                         errors:
     *                           type: array
     *                           items:
     *                             type: string
     *                           description: 错误信息列表
     *       401:
     *         description: 未授权
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     *       403:
     *         description: 权限不足
     *         content:
     *           application/json:
     *             schema:
     *               $ref: '#/components/schemas/ErrorResponse'
     */
    // 批量操作
    this.router.post(
      '/batch/status',
      authMiddleware,
      adminMiddleware,
      this.wrapAsync(this.batchUpdateUserStatus)
    );
  }

  /**
   * 请求密码重置
   */
  private requestPasswordReset = async (ctx: Context): Promise<void> => {
    // TODO: 实现密码重置逻辑
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '密码重置邮件已发送',
    };
  };

  /**
   * 确认密码重置
   */
  private confirmPasswordReset = async (ctx: Context): Promise<void> => {
    // TODO: 实现密码重置确认逻辑
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '密码重置成功',
    };
  };

  /**
   * 验证邮箱
   */
  private verifyEmail = async (ctx: Context): Promise<void> => {
    // TODO: 实现邮箱验证逻辑
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '邮箱验证成功',
    };
  };

  /**
   * 重新发送验证邮件
   */
  private resendVerificationEmail = async (ctx: Context): Promise<void> => {
    // TODO: 实现重新发送验证邮件逻辑
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '验证邮件已重新发送',
    };
  };

  /**
   * 上传头像
   */
  private uploadAvatar = async (ctx: Context): Promise<void> => {
    // TODO: 实现头像上传逻辑
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '头像上传成功',
      data: {
        avatar: 'https://example.com/avatar.jpg'
      }
    };
  };

  /**
   * 删除头像
   */
  private deleteAvatar = async (ctx: Context): Promise<void> => {
    // TODO: 实现头像删除逻辑
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '头像删除成功',
    };
  };

  /**
   * 注销登录
   */
  private logout = async (ctx: Context): Promise<void> => {
    // TODO: 实现注销登录逻辑（如果使用 Redis 存储会话）
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '注销成功',
    };
  };

  /**
   * 批量更新用户状态
   */
  private batchUpdateUserStatus = async (ctx: Context): Promise<void> => {
    // TODO: 实现批量更新用户状态逻辑
    ctx.status = 200;
    ctx.body = {
      success: true,
      message: '批量更新成功',
    };
  };
}

export default UserRouter;